﻿using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebApp.Tasks.Quartz.Jobs;

namespace WebApp.Tasks.Quartz
{
    public class TaskFactory
    {
        public TaskFactory() { }
        public IJobDetail CreateJob(string jobName,string groupName, IDictionary<string, object> jobData)
        {
            var jobDetail = JobBuilder.Create<AssemblyJob>()
               .WithIdentity(jobName, groupName)
               .UsingJobData(new JobDataMap(jobData))
               .Build();
            return jobDetail;

        }
        public void CreateTrigger(IJobDetail jobDetail,string triggerName, string groupName, string cronExpression)
        {
            // 创建触发器  
            var trigger = TriggerBuilder.Create()
                .WithIdentity(triggerName, groupName)
                .StartNow()
                .WithCronSchedule(cronExpression)
                .Build();

            _scheduler.ScheduleJob(jobDetail, trigger);
        }
    }
}
